

function checkForm(){
	var submitFlag = false;
	
	var propertyDemand = document.getElementsByName('propertyDemand');
	var otherPropertyDemand = document.getElementById('otherPropertyDemand').value;
	var checkedPropertyDemandArray = new Array();
	for(var i=0; i<propertyDemand.length; i++){ 
		if(propertyDemand[i].checked){
			checkedPropertyDemandArray.push(propertyDemand[i].value + ":" + propertyDemand[i].nextSibling.nodeValue.substring(0,2));
		}
	}
	if(otherPropertyDemand != '' && otherPropertyDemand != 'undefined') 
		checkedPropertyDemandArray.push('0: ' + otherPropertyDemand);
	$("#checkedPropertyDemand").val(checkedPropertyDemandArray.toString());
	
	var shoppingDemand = document.getElementsByName('shoppingDemand');
	var otherShoppingDemand = document.getElementById('otherShoppingDemand').value;
	var checkedShoppingDemandArray = new Array();
	for(var i=0; i<shoppingDemand.length; i++){ 
		if(shoppingDemand[i].checked){
			checkedShoppingDemandArray.push(shoppingDemand[i].value + ":" + shoppingDemand[i].nextSibling.nodeValue.substring(0,2));
		}
	}
	if(otherShoppingDemand != '' && otherShoppingDemand != 'undefined') 
		checkedShoppingDemandArray.push('0:' + otherShoppingDemand);
	$("#checkedShoppingDemand").val(checkedShoppingDemandArray.toString());
	
/*	if(!customerNameValidate()) return goScroll("customerName");
	if(!customerTypeValidate()) return goScroll("customerType");
	if(!loginAccountValidate()) return goScroll("loginAccount");
	if(!corporateRepresentativeValidate()) return goScroll("corporateRepresentative");
	if(!officeAddressValidation()) return goScroll("officeAddress");
	if(!contactNameValidation()) return goScroll("contactName");
	if(!contactNumberValidation()) return goScroll("contactNumber");
	if(!emailValidation()) return goScroll("email");*/
	if(!passwordValidate()) return goScroll("password");
	return;
}

/**
 * 客户名验证
 */
function customerNameValidate(){
	var flag = false;
	var name = $("#customerName").val();  
	var desc = document.getElementById("customerNameMsg");
	
	if(validation(name, 2, 50, desc, "客户名称")){
		document.getElementById("customerNameMsg").innerHTML = "";	
		if(isSpecialCharacter(name) || name.split(" ").length > 1){
			desc.innerHTML = "<font color='red'>×客户名称仅由字母、数字或汉字组成</font>"
		}/*else{

			$.ajax({
				url : "validate.htmx",
				type:"GET",  
				dataType : 'JSON',
				contentType:'text/html; charset=utf-8;',
				asyn: false,
				async: false,  
				data : {"name" : name },  
				error: function(data){
					alert("系统连接失败，请稍后再试！");
				},
				success : function(data){
					if(data == "success"){
						flag = true;
						desc.innerHTML = "<font color='blue'>√该客户名称可用</font>";	
					}else{
						desc.innerHTML = "<font color='red'>×该客户名称已存在</font>";
					}
				}
			});	
		}*/
	}
	return flag;
}

/**
 * 客户类型验证
 */
function customerTypeValidate(){
	var flag = false;
	var customerType = $("#customerType").val();
	if(customerType == ""){
		document.getElementById("customerTypeMsg").innerHTML = "<font color='red'>×请选择类型</font>";
	}else{
		document.getElementById("customerTypeMsg").innerHTML = "";
		flag = true;
	}	
	return flag;
}

/**
 * 验证登录账号
 */
function loginAccountValidate(){
	var flag = false;
	var loginAccount = document.getElementById("loginAccount").value;
	var desc = document.getElementById("loginAccountMsg");
	if(validation(loginAccount, 2, 50, desc, "登录账号")){
		if(!isNumber(loginAccount)){
			desc.innerHTML = "<font color='red'>×登录账号仅可以由数字组成</font>";
		}else{
			flag = true;
		}
	}
	return flag;
}

/**
 * 法人代表验证
 */
function corporateRepresentativeValidate(){
	var flag = false;
	var corporateRepresentative = document.getElementById("corporateRepresentative").value;
	var desc = document.getElementById("corporateRepresentativeMsg");
	if(validation(corporateRepresentative, 2, 16, desc, "法人代表")){
		if(isSpecialCharacter(corporateRepresentative)){
			desc.innerHTML = "<font color='red'>×法人代表仅可由字母、数字或汉字组成</font>";
		}else{
			flag = true;
		}
	}
	
	return flag;
}


/**
 * 经营品牌验证
 */
/*function brandValidation(){
	var flag = false;
	var brand = document.getElementById("brand").value;
	var desc = document.getElementById("brandMsg");
	if(validation(brand, 2, 50, desc, "经营品牌")){
		if(isSpecialCharacter(brand)){
			desc.innerHTML = "<font color='red'>×经营品牌仅可由字母、数字或汉字组成</font>";
		}else{
			flag = true;
		}
	}
	return flag;
}*/

/**
 * 办公地址验证
 */
function officeAddressValidation(){
	var flag = false;
	var officeAddress = document.getElementById("officeAddress").value;
	var desc = document.getElementById("officeAddressMsg");
	if(validation(officeAddress, 3, 200, desc, "联系地址")){
		if(isSpecialCharacter(officeAddress)){
			desc.innerHTML = "<font color='red'>×联系地址仅可由字母、数字或汉字组成</font>";
		}else{
			flag = true;
		}
	}
	return flag;
}

/**
 * 联系人验证
 */
function contactNameValidation(){
	var flag = false;
	var contactName = document.getElementById("contactName").value;
	var desc = document.getElementById("contactNameMsg");
	if(validation(contactName, 2, 40, desc, "联系人")){
		if(isSpecialCharacter(contactName)){
			desc.innerHTML = "<font color='red'>×联系人仅可由字母、数字或汉字组成</font>";
		}else{
			flag = true;
		}
	}
	return flag;
}

/**
 * 联系电话验证
 */
function contactNumberValidation(){
	var flag = false;
	var contactNumber = document.getElementById("contactNumber").value;
	var desc = document.getElementById("contactNumberMsg");
	if(validation(contactNumber, 5, 20, desc, "联系电话")){
		if(!isNumber(contactNumber)){
			desc.innerHTML = "<font color='red'>×联系电话仅可以由数字组成</font>";
		}else{
			flag = true;
		}
	}
	
	return flag;
}

/**
 * 邮箱验证
 */
function emailValidation(){
	var flag = false;
	var email = document.getElementById("email").value;
	var desc = document.getElementById("emailMsg");
	if(validation(email, 2, 100, desc, "邮箱或微信")){
		/*var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/; 
		if(!reg.test(email)){
			desc.innerHTML = "<font color='red'>×email格式错误</font>";
		}else{
			flag = true;
		}*/
		return true;
	}
	return flag;
}

/**
 * 网址验证
 */
/*function networkAddressValidation(){
	var flag = false;
	var networkAddress = document.getElementById("networkAddress").value;
	var desc = document.getElementById("networkAddressMsg");
	var reg=/^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/;
	if(!reg.test(networkAddress)){
		desc.innerHTML = "<font color='red'>×网址格式错误：请以http://或者https://开头</font>";
	}else{
		flag = true;
	}
	return flag;
}*/

function validation(param, startLen, endLen, desc, str){
	var flag = true;
	if(param == "undefined" || param == null || param.length == 0){
		desc.innerHTML = "<font color='red'>×"+str+"不能为空</font>";
		//desc.css('borderColor','red');
		flag = false;
	}else{
		desc.innerHTML = "";
		if(startLen == endLen && param.length != startLen){
			desc.innerHTML = "<font color='red'>×"+str+"长度必须为" + startLen + "位</font>";
			flag = false;
		}else{
			desc.innerHTML = "";
			if(param.length > endLen || param.length < startLen){
				desc.innerHTML = "<font color='red'>×"+str+"长度必须为" + startLen + "-" + endLen + "位</font>";
				flag = false;
				
			}
			
			var arr = new Array();
			arr = param.split(" ");
			if(arr.length != 1){
			　　desc.innerHTML = "<font color='red'>×"+str+"不能包含空格</font>";
				flag = false;
			}
		}	
	}
	
	return flag;
}

function passwordValidate(){
	var flag = false;
	var password = $("#password").val();
	var confirmPassword = $("#confirmPassword").val();
	if ("" == password) {
		document.getElementById("passwordMsg").innerHTML = "<font color='red'>×密码不能空</font>"
			email
	}else{
		document.getElementById("passwordMsg").innerHTML = "";
		if(password.length < 6 || password.length > 16){
			document.getElementById("passwordMsg").innerHTML = "<font color='red'>×密码长度为6-16位</font>"
		}else if(password != confirmPassword){
			document.getElementById("passwordMsg").innerHTML = "<font color='red'>×两次输入的密码不一致</font>";
		}else{
			document.getElementById("passwordMsg").innerHTML = "<font color='blue'>√密码可用</font>";
			flag = true;
		}
	}
	return flag;
}

/**
 * 判断是否包含特殊字符
 * 
 * @param s
 * @returns
 */
	function isSpecialCharacter(s) 
	{ 
		var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】_‘；：”“'。，、？]") 
		return (pattern.test(s));  
	}
	
	/**
	 * 判断是否仅由数字组成
	 * 
	 * @param value
	 */
	function isNumber(s) {
	    var patrn = /^(-)?\d+(\.\d+)?$/;
	    if (patrn.exec(s) == null || s == "") {
	        return false
	    } else {
	        return true
	    }
	}
	
	/**
	 * 判断是否仅由字母组成
	 * 
	 * @param s
	 */
	function isLetter(s){
		var patrn= /^[A-Za-z]+$/;
		if (patrn.exec(value) == null || value == "") {
	        return false
	    } else {
	        return true
	    }
	}
	
	function ajaxFileUpload(prefix){
		var id = prefix.id;
		var flag = false;
		if($('#'+id).val() == ""){
			alert("您未选择任何图片！！");
			return false;
		}
	}

	function openDialog(id){
		document.getElementById(id).click(); 
	}
	
	function goScroll(param) {
		document.getElementById(param).scrollIntoView();
		return false;
	} 